import random

def generate_data(size=100, max_value=1000, k=None):
    """生成随机数组和k值,可指定k,不指定则随机"""
    arr = [random.randint(0, max_value) for _ in range(size)]
    if k is None:
        k = random.randint(0, min(20, size))
    return arr, k